//
// Created by Administrator on 2021/1/31 0031.
//

#ifndef JQHMUSIC_JQHFFMPEG_H
#define JQHMUSIC_JQHFFMPEG_H


#include "CallJava.h"
#include "JqhAudio.h"
#include <pthread.h>"
#include "JqhPlayStatus.h"

extern "C"{
    #include <libavformat/avformat.h>
    #include <libavutil/time.h>
};


class JqhFFmpeg {
public:
    CallJava *callJava = NULL;
    const char *url = NULL;
    pthread_t  decodeThread;
    AVFormatContext *pFormatCtx = NULL;
    JqhAudio *audio = NULL;
    JqhPlayStatus *playStatus = NULL;
    pthread_mutex_t init_mutex;
    bool  exit = false;
    int duration = 0;
    pthread_mutex_t seek_mutex;

public:
    JqhFFmpeg(JqhPlayStatus *playStatus, CallJava *callJava, const char *url);
    ~JqhFFmpeg();

    void parpared();

    void decodeFFmpegThread();

    void start();

    void pause();

    void resume();

    void release();

    void seek(int64_t secds);

    void setVolume(int percent);

    void setMute(int mute) ;

    void setPitch(float pitch);
    void setSpeed(float speed);
    int getSampleRate();
    void startStopRecord(bool start);
};


#endif //JQHMUSIC_JQHFFMPEG_H
